<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>辅助教学系统登陆页面</title>
<link rel="stylesheet" type="text/css"
	href="themes/bootstrap/easyui.css">
<link rel="stylesheet" type="text/css" href="themes/icon.css">
<link rel="stylesheet" type="text/css" href="themes/color.css">
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="js/easyui-lang-zh_CN.js"></script>
</head>
<script type="text/javascript">

$(function() {
	$('#win').window({
		width : 600,
		height : 400,
		title : '用户登陆界面',
		modal : true,
		collapsible : false,
		minimizable : false,
		maximizable : false,
		closable : false,			
		});
		createCode();
		$('#tb').textbox({
			iconCls : 'icon-man',
			iconAlign : 'left',
		})
		$('#tbe').textbox({
			iconCls : 'icon-lock',
			iconAlign : 'left'
		})

	})
var code ; //在全局 定义验证码   
function createCode(){    
       code = "";   
       var codeLength = 4;//验证码的长度   
       var checkCode = document.getElementById("checkCode");
     //所有候选组成验证码的字符，当然也可以用中文的
       var selectChar = new Array(0,1,2,3,4,5,6,7,8,9,
    	'A','B','C','D','E','F','G','H','I','J','K',
    	'L','M','N','O','P','Q','R','S','T','U','V',
    	'W','X','Y','Z','a','b','c','d','e','f','g',
    	'h','i','j','k','l','m','n','o','p','q','r',
    	's','t','u','v','w','x','y','z');   
       for(var i=0;i<codeLength;i++){   
       var charIndex = Math.floor(Math.random()*62);   
       code +=selectChar[charIndex];   
       }   
       if(checkCode){   
         checkCode.className="code";   
         checkCode.value = code;   
       }   
     } 
//登录
function register(){
	   var uname=$("#tb").val();
	   var upsw=$("#tbe").val();
       var inputCode =$("#input1").val();   
       if(inputCode==code){   
		$.ajax({	   				
				type:"post",
				url:"login",
				data:{"uname":uname,"upsw":upsw},
				dataType:"text",
				success:function(data){
		    		if(data=="true"){
		    			$.messager.alert('提示','登录成功','info',function(){
		    				window.location.href='main.jsp'
			    			}); 			    							 	    					    			
		    		  }else{
		    			  $.messager.alert('提示','登录失败','info',function(){
		    				window.location.href='index.jsp'
		    			  });
		    		  }
		    	}   		   		
		})  
       }   
       else if(inputCode != code ){   
    	  $.messager.alert('提示',"验证码输入错误！");   
          createCode();//刷新验证码   
       }   
       else if(inputCode.length <=0){   
    	   $.messager.alert('提示',"请输入验证码！")

         }            
      } 
      
//验证账号是否存在
$(function(){
		$("input",$("#tb").next("span")).blur(function(){ 
			var uname=$("#tb").val();
			$.ajax({	   				
					type:"post",
					url:"findUname",
					data:{"uname":uname},
					dataType:"text",
					success:function(data){
		    		if(data=="true"){		    			
		    			$("#h1").text("账号正确");
		    		  }else{
		    			$("#h1").text("账号错误,请重新输入");
		    			window.location.href='index.jsp'
		    		  }
		    	}    		   		
			})
		}) 	
	})
//验证密码是否存在
$(function(){
		$("input",$("#tbe").next("span")).blur(function(){ 
			var upsw=$("#tbe").val();
			$.ajax({	   				
					type:"post",
					url:"findUpsw",
					data:{"upsw":upsw},
					dataType:"text",
					success:function(data){
			    		if(data=="true"){
			    			$("#h2").text("密码正确");    					    			
			    		  }else{
			    			$("#h2").text("密码错误，请重新输入");
			    			window.location.href='index.jsp'
			       }
		    	}    		   		
			})
		}) 	
	})	
	
//找回密码	
function forgetUpsw(){	
	$('#dlg').dialog('open').dialog('center').dialog('setTitle','用户重置密码');
	$('#fm').form('clear');
	$('#sd').hide();
}	
		$(function(){
			$("input",$("#newupsw").next("span")).blur(function(){ 
				var newpsw=$("#newpsw").val();
				var newupsw=$("#newupsw").val();
				if(newpsw!=newupsw){
					$.messager.alert('提示','请确保2次密码一致')
				}else{
					 $("#ok").click(function(){
						 uname = $("#uname").val();	
						 var uo=new Object();
						 uo.name = $("#name").val();
						 uo.age = $("#age").val();
						 uo.address = $("#address").val();
						 uo.number = $("#number").val();	 
						 var jso=JSON.stringify(uo);
							$.ajax({	   				
								type:"post",
								url:"forgetUpsw",
								data:{"jso":jso,"uname":uname,"newupsw":newupsw},
								dataType:"text",
								success:function(data){
						    		if(data=="true"){
						    			$.messager.alert('提示','修改成功','info',function(){
						    				$('#dlg').dialog('close'),
						    				window.location.href='index.jsp'
									    });    					    			
						    		  }else{
										 $.messager.alert('提示','修改失败','info',function(){
											 $('#dlg').dialog('close'),
											 window.location.href='index.jsp'
									 });
						       }
					    	}    		   		
						})  
						 
					 })
					 
				}
			}) 	
		})	 

</script>
<body>
	<div id="win">
		<div style="margin-left: 180px; margin-top: 80px">
			<form  method="post" id="fm">
				<input id="tb" type="text" name="uname" value="${cookie.uname.value}"
				style="width: 260px;" required="required" 
				missingMessage="请输入您的账号" /><div><h id="h1" style='color:red'>&nbsp</h></div>
				<br>
				<input id="tbe" type="password" name="upsw" value="${cookie.upsw.value}"
				style="width: 260px" required="required" 
				missingMessage="请输入您的密码" /><div><h id="h2" style='color:red'>&nbsp</h></div>
				<br>
				验证码：<input  type="text"   id="input1" />
				<input type="text" onclick="createCode()" readonly="readonly" 
				id="checkCode" class="unchanged" style="width: 80px"  />
				<br><br>
				<span>
				<input type="checkbox" id="remember" name="remember">记住我&nbsp&nbsp 
				<a href="javascript:void(0)" class="easyui-linkbutton c6" 
				style="width:90px;height:30px" onclick="forgetUpsw()" />忘记密码？</a>
				&nbsp&nbsp
				<a href="javascript:void(0)" class="easyui-linkbutton c6" 
				style="width:90px;height:32px" onclick="register()" />登录</a>							
				</span>						
			</form>
		</div>
	</div>

	      <!-- 找回密码框 -->  
        <div id="dlg" class="easyui-dialog" style="width:400px;height:340px;padding:10px 20px"
            closed="true" buttons="#dlg-buttons">
        <div style="margin-left: 60px"> 
        <div class="ftitle" style="margin-left: 50px">
        <span>找回密码&nbsp
        <h style='color:red'>(注释：(*)为必填框)</h>
        </span>       
        </div>
        <div style="margin-left:10px">  
       	 <form id="fm" method="post" novalidate>     
            <div class="fitem" id="na">
                <label>用户名字(*):</label>
                <input id="name" class="easyui-textbox"
                required="required" missingMessage="请输入您的姓名">
            </div>
            <div class="fitem" id="ag">
                <label>用户年龄(*):</label>
                <input id="age" class="easyui-textbox"
                required="required" missingMessage="请输入您的年龄">
            </div>
            <div class="fitem" id="ad">
                <label>用户地址(*):</label>
                <input id="address" class="easyui-textbox"
                required="required" missingMessage="请输入您的地址">
            </div>
            <div class="fitem" id="nm">
                <label>用户电话(*):</label>
                <input id="number" class="easyui-textbox"
                required="required" missingMessage="请输入您的电话">
            </div>
            <div class="fitem" id="un">
                <label>用户账号(*):</label>
                <input id="uname" class="easyui-textbox"
                required="required" missingMessage="请输入您的账号">
            </div>
            <div class="fitem" id="nup">
                <label>新&nbsp密&nbsp&nbsp码(*):</label>
                <input id="newpsw" class="easyui-textbox" type="password" 
                required="required" missingMessage="请输入新密码">
            </div>
            <div class="fitem" id="up">
                <label>再次输入(*):</label>
                <input id="newupsw" name="newupsw" class="easyui-textbox" 
                type="password" required="required" missingMessage="请再次输入新密码">
            </div>
          </form>
        </div> 
       </div>
    </div>
    <div id="dlg-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok"  style="width:90px;" id="ok">找回</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" 
        onclick="javascript:$('#dlg').dialog('close')" style="width:90px;">取消</a>
    </div>
</body>
    <style type="text/css">  
        .code   
        {   
            background-image:url(code.jpg);   
            font-family:Arial;   
            font-style:italic;   
            color:Red;   
            border:0;   
            padding:2px 3px;   
            letter-spacing:3px;   
            font-weight:bolder;   
        }   
        .unchanged   
        {   
            border:0;   
        }   
    </style> 
</html>